/* eslint-disable */
import fetchJsonp from 'fetch-jsonp'
export default async (url = '', data = {}, param = {}, type = 'GET', method = 'fetchJsonp') => {
  let baseUrl = '';
  type = type.toUpperCase();
  url = baseUrl + url;

  if (type == 'GET') {
    let dataStr = ''; //数据拼接字符串
    Object.keys(data).forEach(key => {
      dataStr += key + '=' + data[key] + '&';
    })

    if (dataStr !== '') {
      dataStr = dataStr.substr(0, dataStr.lastIndexOf('&'));
      url = url + '?' + dataStr;
    }
    return new Promise((resolve, reject) => {
      fetchJsonp(url, param).then(async res => {
        let data =  res.json()
        resolve(data)
      }).catch(e => {
        reject(e)
      })
    })
  }
}